package src.itheima05;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

/**
 * @author xxx
 * @date 2020/12/23 1:47
 * @description
 */
public class Test {
    public static void main(String[] args) throws IOException {
        //通过文件字节输出流获取配置文件内容
        FileInputStream fileInputStream=new FileInputStream("D:\\java349\\day11\\config.properties");
       /* byte[]bytes=new byte[1024];
        int a=0;
        while ((a=fileInputStream.read(bytes))!=-1){
            System.out.println(new String(bytes,0,a));
        }*///读过一边就不再读了

        FileOutputStream fileOutputStream=new FileOutputStream("D:\\java349\\day11\\config.properties");
        fileOutputStream.write("uu=rr".getBytes());
        fileOutputStream.write("\r\n".getBytes());
        fileOutputStream.write("gg=ww".getBytes());
        fileOutputStream.write("\r\n".getBytes());
        fileOutputStream.write("bb=ii".getBytes());
        fileOutputStream.write("\r\n".getBytes());
        fileOutputStream.write("qqqw=ll".getBytes());
        //通过文件字节输入流将内容输入到配置文件里面


        //使用Properties集合读取配置文件里面的所有内容
        Properties properties=new Properties();
        properties.load(fileInputStream);

        //将Properties内的所有键存在set集合里面
        Set<String> set=properties.stringPropertyNames();

        //遍历set集合，获取Properties中所有的值
        for (String s : set) {
            String aa=properties.getProperty(s);
            System.out.println(aa);
        }
        fileInputStream.close();
        fileOutputStream.close();
    }
}
